package SQLx::Querylet::Plugin;

use strict;
use warnings;

use Carp qw( confess );

sub register {
    my $class = shift;
    my ($querylet) = @_;
    confess("Can't register DBD plugin for querylet without DBD") unless $querylet->_get_dbh();
    my $plugin = $class.'::'.$querylet->_get_dbh()->{ Driver }->{ Name };
    eval "require $plugin";
    {
        no strict qw( refs );
        for my $n (keys %{$plugin.'::'}) {
            next if $n eq 'new';
            next unless eval { $plugin->can($n) };
            $querylet->{ callback }->{ $n } = eval('sub { ' . $plugin . '::' . $n . '( @_ ) }');
        }
    }
    return;
}

1;

